package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.health.dao.LakersDao;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.pojo.Lakers;
import com.itheima.health.service.LakersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class LakersServiceImpl implements LakersService {
    @Autowired
    private LakersDao lakersDao;

    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
       log.info("权限管理-分页查询]data：{}",queryPageBean);

       //使用分页插件
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //分页查询数据库
        Page<Lakers> page=lakersDao.selectByConditon(queryPageBean.getQueryString());
        //封装分页数据库
        return new PageResult(page.getTotal(),page.getResult());


    }
    //新增权限
    @Transactional
    @Override
    public void add(Lakers lakers) {
        log.info("[权限管理-添加]data:{}",lakers);
        lakersDao.insert(lakers);
    }
    //根据ID删除
    @Transactional
    @Override
    public void deleteById(Integer id) {
        log.info("[权限管理-根据ID删除]id:{}",id);
        lakersDao.deleteById(id);

    }
    //根据ID查询
    @Override
    public Lakers findById(Integer id) {
        log.info("[权限管理-根据ID查询]id:{}",id);
        return lakersDao.selectById(id);
    }
    //编辑权限
    @Transactional
    @Override
    public void edit(Lakers lakers) {
        log.info("[权限管理-编辑]data:{}",lakers);
        lakersDao.update(lakers);
    }
}
